package org.com.ashen.web;

import com.alibaba.fastjson.JSON;
import org.com.ashen.dal.dataobject.SMSPIN;
import org.com.ashen.dal.mapper.SMSPINMapper;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class UserDaoTest {

	private ApplicationContext applicationContext;
//	private UserMapper userMapper;
//	private PersonMapper personMapper;
	private SMSPINMapper smspinMapper;
	@Test
	public void testGetUserByAccount() {
		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
        smspinMapper = (SMSPINMapper) applicationContext.getBean("SMSPINMapper");
        SMSPIN smspin = new SMSPIN();
        Date sendTime = null;
        try {
            sendTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2022-11-08 15:19:16");
        }catch (Exception e){}
        smspin.setId(1);
        smspin.setCreatetime(new Date());
        smspin.setUserid("aaa");
        smspin.setStatus("0");
        smspin.setMobile("136511");
        String pin = Integer.toString(100000+ new Random().nextInt(900000));
        smspin.setPin(pin);
        System.out.println(JSON.toJSONString(smspin));
		smspinMapper.insert(smspin);
	}
//
//	@Test
//	public void testCountQuery() {
//		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
////		sysUserMapper = (SysUserMapper) applicationContext.getBean("sysUserMapper");
//		//DataSourceBeanBuilder dataSourceBeanBuilder = new DataSourceBeanBuilder("userMapper", "127.0.0.1", "3306", "testbackup", "root", "root");
////		DataSourceBeanBuilder dataSourceBeanBuilder = new DataSourceBeanBuilder("sysUserMapper", "116.62.19.176", "1433", "RTSaasCQZTFTest", "sa", "RootSoft@0200419");
////		DataSourceContext.setDataSource(dataSourceBeanBuilder);
//
////		QueryUserCondition queryUserCondition = new QueryUserCondition();
////		queryUserCondition.setUserName("admin");
////		SysUser sysuser = sysUserMapper.selectByPrimaryKey("1");
////		System.out.println(sysuser.getUsername());
//
//
//		personMapper = (PersonMapper) applicationContext.getBean("personMapper");
//		Map<String, Object> paramMap = new HashMap<String, Object>();
////		paramMap.put("name", "t%");
////		paramMap.put("ageStart", 18);
////		paramMap.put("ageEnd", 40);
////        List<Person> personList = personMapper.find(paramMap);
//        List<Person> personList = personMapper.find2("tony");
////        System.out.println(personList.get(1).getRemark());
//        for (Person person : personList) {
//        		if (person.getPersonInfo() == null) {
//        			System.out.println("a"+person.getRemark().toString());
//
//				}else {
//					System.out.println(person.getPersonInfo().getId().toString());
//
//				}
//					}
//	}
//
//	@Test
//	public void testQuerys() {
//		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
//		SysSessionLogMapper sysSessionLogMapper = (SysSessionLogMapper) applicationContext.getBean("sysSessionLogMapper");
//		SysSessionLog sysSessionLog = new SysSessionLog();
//		sysSessionLog.setReturntime(new Date());
//		sysSessionLog.setReturnkey("dcb605a106fe42b096c3dfd8fc800d23");
//		sysSessionLogMapper.updateByPrimaryKeySelective(sysSessionLog);
//		}

//
//	private static final String URL_FORMATTER="jdbc:oracle:thin:@%s:%s:%s";
//	private static String driverClassName="oracle.jdbc.driver.OracleDriver";
//
//	private static Connection conn;
//
//	public static Connection getRtsaasConnection(String dburl, String port, String dbname, String username, String password) {
//		try {
//
//			Class.forName(driverClassName);
//			String url = String.format(URL_FORMATTER,dburl,port,dbname);
//			conn = DriverManager.getConnection(url, username, password);
//			return conn;
//		} catch (Exception e) {
//			throw new BusinessException(ErrorEnum.DATASOURCE_NULL);
//		}
//	}



//	@Test
//	public void testQuery() {
//		Date day=new Date();
//
//		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//		System.out.println(df.format(day));

//	applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
//	VsysModuleMapper sysModuleMapper = (VsysModuleMapper) applicationContext.getBean("vsysModuleMapper");
//	SaasAppSessionParam saasAppSessionParam = new SaasAppSessionParam();
//	saasAppSessionParam.setDbid("CQZTFtest");
//	saasAppSessionParam.setLoginid("陈的");
//	List<VsysModule> vsysModules = sysModuleMapper.find(saasAppSessionParam);
//	for (int i = 0; i < vsysModules.size(); i++) {
//		System.out.println(vsysModules.get(i).getModcode());
//	}

//		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
//		AppModuleMapper appModuleMapper = (AppModuleMapper) applicationContext.getBean("appModuleMapper");
//
//		List<AppModule> vsysModules = appModuleMapper.selectByApp("tms3f");
//		for (int i = 0; i < vsysModules.size(); i++) {
//			System.out.println(vsysModules.get(i).getModcode());
//		}
//		}



//
//	@Test
//	public void testCreateUser() {
////		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
////		userMapper = (UserMapper) applicationContext.getBean("userMapper");
//////		DataSourceBeanBuilder dataSourceBeanBuilder = new DataSourceBeanBuilder("userMapper", "127.0.0.1", "3306", "testbackup", "root", "root");
//////		DataSourceContext.setDataSource(dataSourceBeanBuilder);
////
////		UserDO userDO = new UserDO();
////		userDO.setAccount("students");
////		userDO.setPassword("123");
////		userDO.setRole(3);
////		userDO.setUsername("小红");
////		userDO.setGmtCreate(new Date());
////		userDO.setGmtModified(new Date());
////		int i =  userMapper.createUser(userDO);
////
////		System.out.println(i);
//	}
//
//
//		@Test
//		public void testDeleteUserByAccount() {
//			applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
//			TempInfolistMapper tempInfolistMapper = (TempInfolistMapper) applicationContext.getBean("tempInfolistMapper");
//			DataSourceBeanBuilder dataSourceBeanBuilder = new DataSourceBeanBuilder("tempInfolistMapper", "116.62.19.176", "1433", "RTSaasCQZTF_DEV", "sa", "RootSoft@0200419");
//			DataSourceContext.setDataSource(dataSourceBeanBuilder);
//			List<TempInfolist> tempInfolis = tempInfolistMapper.selectAll("1767E378FB3A4676A7808F71E946402E");
//			System.out.println(tempInfolis.size());
//		}

//	@Test
//	public void testDeleteUserByAccount() {
//		applicationContext = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
//		InfoBmMapper infoBmMapper = (InfoBmMapper) applicationContext.getBean("infoBmMapper");
//		InfoBm infoBm = new InfoBm();
//		infoBm.setBmdm("006");
//		infoBm.setBmmc("adaa");
//		infoBm.setGsdm("0001");
//		infoBm.setSys("0");
//		infoBm.setZt("0");
//		infoBm.setDel("0");
//		infoBm.setWmsBmdm("006");
//		infoBm.setWmsBmmc("ad");
//		int i =  infoBmMapper.updateByPrimaryKey(infoBm);
//	}



}
